package SarasGlass;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yerong
 */

import java.util.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
public class form extends javax.swing.JFrame {

    /**
     * Creates new invoice form
     */
    /**
     * Creates item objects
     */
    item item1 = new item(1,0,225);
    item item2 = new item(2,0,185);
    item item3 = new item(3,0,155);
    
    /**
    * Creates About form and the error message form
    */
    About about = new About(this, true);
    Errmg error = new Errmg(this, true);
    
    DecimalFormat dollar = new DecimalFormat("$0.00 ");
    public form() {
        initComponents();
        this.setLocationRelativeTo(null);
        //Set the Calculate button as default. It fires when you press "Enter."
        this.getRootPane().setDefaultButton(calculateJButton);
        // Add icon
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("src/SarasGlass/Splash.png"));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundJPanel = new javax.swing.JPanel();
        titleJLabel = new javax.swing.JLabel();
        infoJPanel = new javax.swing.JPanel();
        IDJLabel = new javax.swing.JLabel();
        dateJLabel = new javax.swing.JLabel();
        dateJTextField = new javax.swing.JTextField();
        IDJFormattedTextField = new javax.swing.JFormattedTextField();
        optionJPanel = new javax.swing.JPanel();
        pieceJLabel = new javax.swing.JLabel();
        quantityJLabel = new javax.swing.JLabel();
        priceJLabel = new javax.swing.JLabel();
        extendedJLabel = new javax.swing.JLabel();
        item1JLabel = new javax.swing.JLabel();
        item1JSpinner = new javax.swing.JSpinner();
        item1priceJLabel = new javax.swing.JLabel();
        item1totalJLabel = new javax.swing.JLabel();
        item2JLabel = new javax.swing.JLabel();
        item2JSpinner = new javax.swing.JSpinner();
        item2priceJLabel = new javax.swing.JLabel();
        item2totalJLabel = new javax.swing.JLabel();
        item3JLabel = new javax.swing.JLabel();
        item3JSpinner = new javax.swing.JSpinner();
        item3priceJLabel = new javax.swing.JLabel();
        item3totalJLabel = new javax.swing.JLabel();
        controlJPanel = new javax.swing.JPanel();
        calculateJButton = new javax.swing.JButton();
        clearJButton = new javax.swing.JButton();
        quitJButton = new javax.swing.JButton();
        subJLabel = new javax.swing.JLabel();
        taxJLabel = new javax.swing.JLabel();
        totalJlabel = new javax.swing.JLabel();
        ValsubJLabel = new javax.swing.JLabel();
        ValtaxJLabel = new javax.swing.JLabel();
        ValtotalJLabel = new javax.swing.JLabel();
        JMenuBar = new javax.swing.JMenuBar();
        fileJMenu = new javax.swing.JMenu();
        clearJMenuItem = new javax.swing.JMenuItem();
        printJMenuItem = new javax.swing.JMenuItem();
        quitJMenuItem = new javax.swing.JMenuItem();
        helpJMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sara's Glass Work");
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(255, 255, 0));
        setForeground(new java.awt.Color(255, 255, 0));
        setSize(new java.awt.Dimension(111, 11));

        backgroundJPanel.setBackground(new java.awt.Color(255, 255, 0));

        titleJLabel.setBackground(new java.awt.Color(255, 255, 0));
        titleJLabel.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        titleJLabel.setForeground(new java.awt.Color(255, 0, 0));
        titleJLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SarasGlass/Bunny.png"))); // NOI18N
        titleJLabel.setText("Sara's Glass Works Invoice");

        infoJPanel.setBackground(new java.awt.Color(255, 255, 0));
        infoJPanel.setForeground(new java.awt.Color(255, 255, 0));

        IDJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        IDJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        IDJLabel.setText("Invoice Number:");
        IDJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        dateJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        dateJLabel.setText("Date:");
        dateJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        dateJTextField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        dateJTextField.setText(sf.format(date));
        dateJTextField.setEnabled(false);

        try {
            IDJFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        IDJFormattedTextField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout infoJPanelLayout = new javax.swing.GroupLayout(infoJPanel);
        infoJPanel.setLayout(infoJPanelLayout);
        infoJPanelLayout.setHorizontalGroup(
            infoJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoJPanelLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(IDJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(IDJFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
                .addComponent(dateJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30))
        );
        infoJPanelLayout.setVerticalGroup(
            infoJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(infoJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(IDJLabel)
                    .addComponent(dateJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dateJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(IDJFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        IDJFormattedTextField.getAccessibleContext().setAccessibleName("");

        optionJPanel.setBackground(new java.awt.Color(255, 255, 51));
        optionJPanel.setForeground(new java.awt.Color(255, 255, 0));

        pieceJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        pieceJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        pieceJLabel.setText("Art Piece:");
        pieceJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        quantityJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        quantityJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        quantityJLabel.setText("Quantity:");
        quantityJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        priceJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        priceJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        priceJLabel.setText("Price:");
        priceJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        extendedJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        extendedJLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        extendedJLabel.setText("Extended Total:");
        extendedJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        item1JLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SarasGlass/1.png"))); // NOI18N
        item1JLabel.setToolTipText("Star Night, 10 pieces left. $225 each");

        item1JSpinner.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item1JSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
        item1JSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                item1JSpinnerStateChanged(evt);
            }
        });

        item1priceJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item1priceJLabel.setText("$225.00");
        item1priceJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        item1totalJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item1totalJLabel.setText("$0.00");
        item1totalJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        item1totalJLabel.setPreferredSize(new java.awt.Dimension(52, 17));

        item2JLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SarasGlass/2.png"))); // NOI18N
        item2JLabel.setToolTipText("Modern Sketch , 20 pieces left. $185 each");

        item2JSpinner.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item2JSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 20, 1));
        item2JSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                item2JSpinnerStateChanged(evt);
            }
        });

        item2priceJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item2priceJLabel.setText("$185.00");
        item2priceJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        item2totalJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item2totalJLabel.setText("$0.00");
        item2totalJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        item2totalJLabel.setPreferredSize(new java.awt.Dimension(52, 17));

        item3JLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SarasGlass/3.png"))); // NOI18N
        item3JLabel.setToolTipText("Mountain, 6 pieces left.  $155 each");

        item3JSpinner.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item3JSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 6, 1));
        item3JSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                item3JSpinnerStateChanged(evt);
            }
        });

        item3priceJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item3priceJLabel.setText("$155.00");
        item3priceJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        item3totalJLabel.setBackground(new java.awt.Color(255, 255, 0));
        item3totalJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        item3totalJLabel.setText("$0.00");
        item3totalJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        item3totalJLabel.setOpaque(true);
        item3totalJLabel.setPreferredSize(new java.awt.Dimension(52, 17));

        javax.swing.GroupLayout optionJPanelLayout = new javax.swing.GroupLayout(optionJPanel);
        optionJPanel.setLayout(optionJPanelLayout);
        optionJPanelLayout.setHorizontalGroup(
            optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionJPanelLayout.createSequentialGroup()
                .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionJPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(optionJPanelLayout.createSequentialGroup()
                                .addComponent(item2JLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                                .addGap(37, 37, 37))
                            .addGroup(optionJPanelLayout.createSequentialGroup()
                                .addComponent(item1JLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(optionJPanelLayout.createSequentialGroup()
                        .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(optionJPanelLayout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addComponent(pieceJLabel))
                            .addGroup(optionJPanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(item3JLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(optionJPanelLayout.createSequentialGroup()
                        .addComponent(item1JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(item1priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, optionJPanelLayout.createSequentialGroup()
                        .addComponent(item2JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(item2priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, optionJPanelLayout.createSequentialGroup()
                        .addComponent(item3JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(item3priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, optionJPanelLayout.createSequentialGroup()
                        .addComponent(quantityJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                        .addComponent(priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(30, 30, 30)
                .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(extendedJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(item1totalJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(item3totalJLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                        .addComponent(item2totalJLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        optionJPanelLayout.setVerticalGroup(
            optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionJPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pieceJLabel)
                    .addComponent(quantityJLabel)
                    .addComponent(priceJLabel)
                    .addComponent(extendedJLabel))
                .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionJPanelLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(item1priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(item1JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(item1totalJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(42, 42, 42)
                        .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(item2totalJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(item2JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(item2priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(43, 43, 43)
                        .addGroup(optionJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(item3totalJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(item3priceJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(item3JSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(optionJPanelLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(item1JLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(item2JLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(item3JLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        item2JLabel.getAccessibleContext().setAccessibleDescription("Modern Sketch , 20 pieces left. $185 each");

        controlJPanel.setBackground(new java.awt.Color(255, 255, 0));
        controlJPanel.setForeground(new java.awt.Color(225, 225, 0));

        calculateJButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        calculateJButton.setMnemonic('C');
        calculateJButton.setText("Calculate");
        calculateJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateJButtonActionPerformed(evt);
            }
        });

        clearJButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        clearJButton.setMnemonic('l');
        clearJButton.setText("Clear");
        clearJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearJButtonActionPerformed(evt);
            }
        });

        quitJButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        quitJButton.setMnemonic('Q');
        quitJButton.setText("Quit");
        quitJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitJButtonActionPerformed(evt);
            }
        });

        subJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        subJLabel.setText("SubTotal:");
        subJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        taxJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        taxJLabel.setText("Tax:");
        taxJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        totalJlabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        totalJlabel.setText("Total:");
        totalJlabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        ValsubJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ValsubJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        ValtaxJLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ValtaxJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        ValtotalJLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        ValtotalJLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout controlJPanelLayout = new javax.swing.GroupLayout(controlJPanel);
        controlJPanel.setLayout(controlJPanelLayout);
        controlJPanelLayout.setHorizontalGroup(
            controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlJPanelLayout.createSequentialGroup()
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(calculateJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(controlJPanelLayout.createSequentialGroup()
                        .addComponent(clearJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(quitJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(taxJLabel)
                    .addComponent(subJLabel)
                    .addComponent(totalJlabel))
                .addGap(34, 34, 34)
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ValsubJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                    .addComponent(ValtaxJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ValtotalJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(42, 42, 42))
        );
        controlJPanelLayout.setVerticalGroup(
            controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlJPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, controlJPanelLayout.createSequentialGroup()
                        .addComponent(calculateJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(clearJButton)
                        .addComponent(quitJButton)))
                .addGap(55, 55, 55))
            .addGroup(controlJPanelLayout.createSequentialGroup()
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(subJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ValsubJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(taxJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ValtaxJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(controlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalJlabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ValtotalJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout backgroundJPanelLayout = new javax.swing.GroupLayout(backgroundJPanel);
        backgroundJPanel.setLayout(backgroundJPanelLayout);
        backgroundJPanelLayout.setHorizontalGroup(
            backgroundJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(optionJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(backgroundJPanelLayout.createSequentialGroup()
                .addGroup(backgroundJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(backgroundJPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(infoJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(backgroundJPanelLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(controlJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(15, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundJPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(titleJLabel)
                .addGap(111, 111, 111))
        );
        backgroundJPanelLayout.setVerticalGroup(
            backgroundJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundJPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(infoJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(optionJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(controlJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(617, 617, 617))
        );

        JMenuBar.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N

        fileJMenu.setMnemonic('F');
        fileJMenu.setText("File");

        clearJMenuItem.setMnemonic('l');
        clearJMenuItem.setText("Clear");
        clearJMenuItem.setToolTipText("");
        clearJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearJMenuItemActionPerformed(evt);
            }
        });
        fileJMenu.add(clearJMenuItem);

        printJMenuItem.setMnemonic('P');
        printJMenuItem.setText("Print");
        printJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printJMenuItemActionPerformed(evt);
            }
        });
        fileJMenu.add(printJMenuItem);

        quitJMenuItem.setMnemonic('Q');
        quitJMenuItem.setText("Quit");
        quitJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitJMenuItemActionPerformed(evt);
            }
        });
        fileJMenu.add(quitJMenuItem);

        JMenuBar.add(fileJMenu);

        helpJMenu.setMnemonic('H');
        helpJMenu.setText("Help");

        jMenuItem1.setText("About");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        helpJMenu.add(jMenuItem1);

        JMenuBar.add(helpJMenu);

        setJMenuBar(JMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 512, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * Quit program
    * @autor Yerong
    * @param evt 
    */
    private void quitJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitJButtonActionPerformed
        // Terminate the application
        System.exit(0);
    }//GEN-LAST:event_quitJButtonActionPerformed

    /**
    * Clear button
    * @author Yerong
    * @param evt 
    */
    private void clearJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearJButtonActionPerformed
        // Clear number values in spinners
        item1JSpinner.setValue(0);
        item2JSpinner.setValue(0);
        item3JSpinner.setValue(0);
        // Clear the amount in control panel
        ValsubJLabel.setText("");
        ValtaxJLabel.setText("");
        ValtotalJLabel.setText("");
        IDJFormattedTextField.requestFocus();
    }//GEN-LAST:event_clearJButtonActionPerformed

/**
 * Clear Menu item
 * @param evt 
 * @author Yerong
 */
    private void clearJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearJMenuItemActionPerformed
        // Clear number values in spinners
        item1JSpinner.setValue(0);
        item2JSpinner.setValue(0);
        item3JSpinner.setValue(0);
        // Clear the amount in control panel
        ValsubJLabel.setText("");
        ValtaxJLabel.setText("");
        ValtotalJLabel.setText("");
        IDJFormattedTextField.requestFocus();
    }//GEN-LAST:event_clearJMenuItemActionPerformed

/**
 * Calculate Button
 * @param evt 
 * @author Yerong
 */
    private void calculateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateJButtonActionPerformed
        //Check whether invoice numbers are valid
        String temp = IDJFormattedTextField.getText();
        if("    ".equals(temp) || temp.length() < 4){ 
            System.out.println("DEBUG"); //DEBUG
            //System.exit(0);
            error.setVisible(true);
            IDJFormattedTextField.requestFocus();}
        else{
        // Get the input invoice number
        int id = Integer.parseInt(
            IDJFormattedTextField.getText());
        //Create an new invoice object
        double sub = 0.0, tax =0.0, total=0.0;
        invoice newInvoice = new invoice();
        // Do the calculation with the object newInvoice 
        newInvoice.calculate(id, item1, item2, item3);
        sub = newInvoice.get_sub();
        tax = newInvoice.get_tax();
        total = newInvoice.get_total();
        // Set text to three labels : subtotal, tax, total
        ValsubJLabel.setText(dollar.format(sub));
        ValtaxJLabel.setText(dollar.format(tax));
        ValtotalJLabel.setText(dollar.format(total));
        }
    }//GEN-LAST:event_calculateJButtonActionPerformed

/**
 * Dynamically read from JSpinner1
 * @param evt
 * @author Yerong
 */
    private void item1JSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_item1JSpinnerStateChanged
        int num1=(Integer)item1JSpinner.getValue();
        int value1=num1*225;
        item1.set_quantity(num1);
        item1.set_sub(value1);
        item1totalJLabel.setText("$"+value1+".00");
    }//GEN-LAST:event_item1JSpinnerStateChanged

/**
 * Dynamically read from JSpinner2
 * @param evt 
 * @author Yerong
 */  
    private void item2JSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_item2JSpinnerStateChanged
        int num2=(Integer)item2JSpinner.getValue();
        int value2=num2*185;
        item2.set_quantity(num2);
        item2.set_sub(value2);
        item2totalJLabel.setText("$"+value2+".00");
    }//GEN-LAST:event_item2JSpinnerStateChanged

/**
 * Dynamically read from JSpinner1
 * @param evt 
 * @author Yerong
 */    
    private void item3JSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_item3JSpinnerStateChanged
        int num3 = (Integer) item3JSpinner.getValue();
        int value3 = num3 * 155;
        item3.set_quantity(num3);
        item3.set_sub(value3);
        item3totalJLabel.setText("$" + value3 + ".00");
    }//GEN-LAST:event_item3JSpinnerStateChanged

    private void printJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printJMenuItemActionPerformed
        // TODO add your handling code here:
        PrintUtilities.printComponent(this);
    }//GEN-LAST:event_printJMenuItemActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        about.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void quitJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitJMenuItemActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_quitJMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new form().setVisible(true);
            }
        });
    }
    Date date = new Date();
    SimpleDateFormat sf = new SimpleDateFormat("MM/dd/yyyy");
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField IDJFormattedTextField;
    private javax.swing.JLabel IDJLabel;
    private javax.swing.JMenuBar JMenuBar;
    private javax.swing.JLabel ValsubJLabel;
    private javax.swing.JLabel ValtaxJLabel;
    private javax.swing.JLabel ValtotalJLabel;
    private javax.swing.JPanel backgroundJPanel;
    private javax.swing.JButton calculateJButton;
    private javax.swing.JButton clearJButton;
    private javax.swing.JMenuItem clearJMenuItem;
    private javax.swing.JPanel controlJPanel;
    private javax.swing.JLabel dateJLabel;
    private javax.swing.JTextField dateJTextField;
    private javax.swing.JLabel extendedJLabel;
    private javax.swing.JMenu fileJMenu;
    private javax.swing.JMenu helpJMenu;
    private javax.swing.JPanel infoJPanel;
    private javax.swing.JLabel item1JLabel;
    private javax.swing.JSpinner item1JSpinner;
    private javax.swing.JLabel item1priceJLabel;
    private javax.swing.JLabel item1totalJLabel;
    private javax.swing.JLabel item2JLabel;
    private javax.swing.JSpinner item2JSpinner;
    private javax.swing.JLabel item2priceJLabel;
    private javax.swing.JLabel item2totalJLabel;
    private javax.swing.JLabel item3JLabel;
    private javax.swing.JSpinner item3JSpinner;
    private javax.swing.JLabel item3priceJLabel;
    private javax.swing.JLabel item3totalJLabel;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel optionJPanel;
    private javax.swing.JLabel pieceJLabel;
    private javax.swing.JLabel priceJLabel;
    private javax.swing.JMenuItem printJMenuItem;
    private javax.swing.JLabel quantityJLabel;
    private javax.swing.JButton quitJButton;
    private javax.swing.JMenuItem quitJMenuItem;
    private javax.swing.JLabel subJLabel;
    private javax.swing.JLabel taxJLabel;
    private javax.swing.JLabel titleJLabel;
    private javax.swing.JLabel totalJlabel;
    // End of variables declaration//GEN-END:variables
}
